import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Main extends JFrame implements ActionListener {
	private Game game = new Game();
	private static ScoreLabel score1 = new ScoreLabel(1);
	private static ScoreLabel score2 = new ScoreLabel(2);
	private JLabel buttonLabel = new JLabel();
	private JButton newGame = new JButton();
	private JButton exitGame = new JButton();
	
	public Main() {
		setTitle("Capture The Flag. ver 0.001                            -Christophe van Baalen");
		setResizable(false);
		setLayout(new BorderLayout());
		game.setPreferredSize(new Dimension(1000, 500));
		game.setBackground(Color.white);
		game.setBorder(BorderFactory.createLineBorder(Color.black));

		//Buttonlabel̈́:
		buttonLabel.setLayout(new FlowLayout());
		buttonLabel.setPreferredSize(new Dimension(1000, 50));
		newGame.setText("New Game");
		exitGame.setText("Exit");
		
		newGame.addActionListener(this);
		exitGame.addActionListener(this);
		
		//Add the buttons and the Labels.
		buttonLabel.add(newGame);
		buttonLabel.add(exitGame);
				
		add(buttonLabel, BorderLayout.SOUTH);
		add(score1, BorderLayout.WEST);
		add(score2, BorderLayout.EAST);
		add(game);
		pack();
		setVisible(true);
	}
	
	public static void main (String[] arg) {
		new Main();
	}
	
	public static void setScore(int p1, int p2) {
		score1.setScore(p1);
		score2.setScore(p2);
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == newGame) {
			add(new Game());
			game.resetGame();
			score1.setScore(0);
			score2.setScore(0);
		}
		else if (e.getSource() == exitGame) {
			System.exit(NORMAL);
		}
	}
}
